<template>
	<view class="content fofa poRel" :style="'background-color: '+back+';'">
		<view class="dis disAl " @click="shouyin" :style="'position: fixed;height: 80rpx;top: '+tops*2+'rpx;left: 30rpx;'">
			<image src="../../static/wc/shouye.png" style="width: 50rpx;height: 50rpx;"></image>
		</view>
		<view :style="'height: '+(tops*2+100)+'rpx;'"></view>
		<view class="wid90 mar coFFF">
			<view class="dis disAl foSi40">
				<view style="width: 20%;" class="dis disAl disJuC">
					<image src="../../static/wc/saoma.png" style="width: 80rpx;height: 80rpx;"></image>
				</view>
				<view>{{list.tips}}</view>
			</view>
			<view class="dis disAl foSi30 mar-top10">
				<view style="width: 20%;"></view>
				<view>扫描下方二维码补充信息</view>
			</view>
		</view>
		<view class="wid90 mar bacFFF borRad20 mar-top40">
			<view class="wid90 mar">
				<view style="height: 20rpx;"></view>
				<view class="hei80 dis disAl disJuC foSi35 fowe600" :style="'color: '+back+';'">线上签约，一键启动</view>
				<view class="mar-top20" :style="'border: 1px dashed '+back+';'"></view>
				<view style="margin-top: 8rpx;" :style="'border: 1px dashed '+back+';'"></view>
				<view class="hei80 dis disAl foSi30 fowe600 mar-top20">
					<view style="color: #8B8989;">合同名称</view>
					<view class="mar-left30">{{list.contract_name}}</view>
				</view>
				<view v-for="(item,index) in list.recipient" :key="index"
				class="hei80 dis disAl foSi30 fowe600" :style="item.roleName?'':'color: #8B8989;'">
					<view style="color: #8B8989;">签署方</view>
					<view class="mar-left30">{{item.roleName?item.roleName:'待补充信息'}}</view>
				</view>
			</view>
			<view class="dis disAl disJuC hei80 foSi30 mar-top20" style="color: #8B8989;">扫码签合同</view>
			<view class="dis disAl disJuC mar-top20">
				<image :src="erImage" style="width: 360rpx;height: 360rpx;"></image>
			</view>
			<view style="height: 40rpx;"></view>
		</view>
		<view v-if="userinfo.usertype" class="wid90 mar dis disAl disJuB foSi35 mar-top30">
			<view class="hei80 dis disAl disJuC borRad10 bacFFF" :style="'color: '+back+';'" @click="fenxiang"
				style="width: 300rpx;">发送给对方</view>
			<view class="hei80 dis disAl disJuC borRad10 bacFFF" :style="'color: '+back+';'" @click="buchong"
			 style="width: 300rpx;">补充信息</view>
		</view>
		<view v-if="!userinfo.usertype" class="wid90 mar dis disAl disJuC foSi35 mar-top30">
			<view class="hei80 wid100 dis disAl disJuC borRad10 bacFFF" :style="'color: '+back+';'" @click="buchong">补充信息</view>
		</view>
		<view class="wid90 mar dis disAl disJuC hei80 foSi25" :style="'color: '+back+';'" @click="tiaozhuan('/pages/template/particularsContract?flowid='+list.flowId)">
			<view>查看合同详情</view>
			<uni-icons size="20" :color="back" type="right"></uni-icons>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				back: uni.getStorageSync('back'),
				backTwo: uni.getStorageSync('backTwo'),
				pdfurl: '',
				tops: '',
				erImage: '',
				list: [],
				mobile: '',
				userinfo: {}
			}
		},
		onLoad(option) {
			this.pdfurl = uni.getStorageSync('contract_detail')
			this.userinfo = uni.getStorageSync('inuse_userinfo');
			console.log('userinfo=', this.userinfo)
			console.log('pdfurl=', this.pdfurl)
			let that = this
			that.getList()
			that.getMobile()
		},
		created() {
			uni.getSystemInfo({
				success: (e) => {
					console.log(e)
					this.tops = e.statusBarHeight
				}
			})
		},
		methods: {
			getMobile(){
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_token_to_userinfo',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {type: 1},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							that.mobile = result.data.mobile
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			buchong(){
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_contracts_createsignurls_public',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {flowid: uni.getStorageSync('flowId')},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							var data = result.data
							for (var i=0; i< data.length; i++) {
								if(that.mobile == data[i].mobile){
									that.goNativeindex(data[i].signUrl)
								}
							}
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			goNativeindex(path){
				console.log(path)
			    uni.openEmbeddedMiniProgram({
			        appId: 'wxa023b292fd19d41d',// 此为 appid
			        path: path,// 此为路径
			        envVersion:"release",
			        success: res => {
			             // 打开成功
			             console.log("打开成功", res);
			        },
			        fail: err => {
			             console.log(err);
			        }
			    })
			},
			fenxiang(){
				let that = this
				wx.downloadFile({
				   url: that.erImage,
				   success: (res) => {
					 wx.showShareImageMenu({
					   path: res.tempFilePath
					 })
				   }
				})
			},
			getList() {
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_current_details',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {flowid: uni.getStorageSync('flowId')},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							that.list = result.data
							that.cun()
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			cun(){
				let that = this
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_save_flowid_to_did',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {flowId: uni.getStorageSync('flowId')},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							that.erweima(result.data)
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			erweima(id) {
				let that = this
				var path = 'pages/index/index'
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_contracts_qrcode',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token': uni.getStorageSync('inuse_userinfo_token')},
					data: {page: path, scene: id},
					success(res) {
					    let result = res.data
					    if(result.code == 1){
							console.log(result.data)
							that.erImage = result.data
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none',
								duration: 2000
					        })
					    }
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				});
			},
			shouyin(){
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
	}
</style>